package com.luck.easyfoodbatch.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.luck.easyfoodbatch.R;
import com.luck.easyfoodbatch.custom.RoundedImageView;
import com.luck.easyfoodbatch.glide.GlideCircleTransform;
import com.luck.easyfoodbatch.mvp.model.ReturnShopCollect;
import com.luck.easyfoodbatch.util.HttpUtil;
import com.luck.easyfoodbatch.util.Tools;
import com.luck.easyfoodbatch.util.XLHRatingBar;
import com.luck.easyrecyclerview.adapter.BaseViewHolder;
import com.luck.easyrecyclerview.adapter.RecyclerArrayAdapter;

/**
 * author：luck
 * project：LoveCare
 * package：com.tongyu.luck.lovecare.adapter
 * email：893855882@qq.com
 * data：16/8/12
 */
public class CollectionShopAdapter extends RecyclerArrayAdapter<ReturnShopCollect.DataBean.ModelsBean> {
    private Context mContext;

    public CollectionShopAdapter(Context context) {
        super(context);
        this.mContext = context;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {

        return new CouponViewHolder(parent);
    }

    public class CouponViewHolder extends BaseViewHolder<ReturnShopCollect.DataBean.ModelsBean> {
        RoundedImageView imageView;
        TextView tv_name;
        XLHRatingBar ratingBar3;

        public CouponViewHolder(ViewGroup parent) {
            super(parent, R.layout.collectionshop_item);
            imageView = $(R.id.riv_avatar);
            tv_name = $(R.id.tv_name);
            ratingBar3 = $(R.id.ratingBar3);
        }

        @Override
        public void setData(final ReturnShopCollect.DataBean.ModelsBean bean, int position) {
            ReturnShopCollect.DataBean.ModelsBean.ShopsBean item = bean.getShops();
            String shop_name = item.getShop_name();
            String shop_avatar = item.getShop_avatar();
            int score = item.getScore();
            if (!Tools.isNull(shop_name)) {
                tv_name.setText(shop_name);
            } else {
                tv_name.setText("");
            }
            if (!Tools.isNull(shop_avatar)) {
                Glide.with(mContext)
                        .load(HttpUtil.IMG_BASE_URL + shop_avatar)
                        .centerCrop()
                        .placeholder(R.mipmap.loading_4b3)
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .transform(new GlideCircleTransform(mContext))
                        .into(imageView);
            } else {
                imageView.setImageResource(R.mipmap.loading_4b3);
            }
            ratingBar3.setCountSelected(score);
        }
    }
}
